<template>
    <div class="comment-list">
        <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
            <van-cell v-for="(item,index) in list" :key="index" :title="item.content" />
        </van-list>
    </div>
</template>

<script>
import {getComments} from "@/api/comment.js"
export default {
    props:{
        source:{
            type:[Number,String,Object],
            requires:true
        }
    },
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      offset:null
    };
  },
  methods: {
    async onLoad() {
      try {
        const {data} = await getComments({
            type:'a',
            source:this.source,
            offset:this.offset,
            limit:10,
        })
        const {results} = data.data;
        console.log(data.data)
        this.list.push(...results)
        this.loading=false;
        if(results.length){
            this.offset=data.data.last_id
        }else{
            this.finished=true
        }
      } catch (error) {
        
      }
    },
  },
};
</script>

<style lang="scss" scoped>
</style>